package t1005;

import java.util.Scanner;

/**
 * @姓名 张东升
 * @日期 2025年03月2025/3/24日、
*/
public class Main {

    public static int linkListCount;
    public static int oddNumberCount;

    public static void main(String[] args) {
        //初始化头节点
        Node head = new Node();
        Scanner sc = new Scanner(System.in);
        createLinkList(sc,head);
        sort(head);
        System.out.println("The length:"+linkListCount);
        System.out.print("The elements:");
        display(head);
        delOddNumber(head);
        System.out.println("Count of deleted odds:"+ oddNumberCount);
        System.out.println("The length:"+(linkListCount-oddNumberCount));
        System.out.print("The elements:");
        display(head);
    }



    //创建连表
    public static void createLinkList(Scanner scanne,Node head){
        Node temp = head;
        int count = 0;
        int n = scanne.nextInt();
        while (n!=0){
            count ++;
            temp.next = new Node(n,null);
            temp = temp.next;
             n = scanne.nextInt();
        }
        linkListCount = count;
    }

    public static void display(Node head){
        Node next = head.next;
        while (next!=null){
            System.out.print(next.data + " ");
            next = next.next;
        }
        System.out.println();
    }
// 1 5 7 32 34 42 56 233
    public static void delOddNumber(Node head){
        int count = 0;
        Node pre  = head;
        Node temp = pre.next;
        while (temp !=null){
             if (temp.data % 2 != 0){
                 pre.next = temp.next;
                 count++;
             }else {
                 // 如果相同就防止漏掉偶数
                 pre = temp;
             }
            temp = temp.next;
        }
        oddNumberCount = count;
    }


    //排序 42 5 32 56 34 7 233 1 0
    public static void sort(Node head){
        Node pre = head.next;
        Node next =  pre.next;
        for (int i = 0; i < linkListCount; i++) {
            while (next!= null){
                if (pre.data > next.data){
                    int temp = pre.data;
                    pre.data = next.data;
                    next.data = temp;
                }
                pre = next;
                next = next.next;
            }
            pre = head.next;
            next =  pre.next;;
        }
    }


}

class Node{
    public int data;
    public Node next;

    public Node() {
    }

    public Node(int data, Node next) {
        this.data = data;
        this.next = next;
    }
}
